public class DeleteDuplicates {
    //完全删除重复节点
    public ListNode deleteDuplicates(ListNode head) {
        if(head==null||head.next==null){
            return head;
        }
        ListNode newHead = new ListNode(0);
        newHead.next = head;
        ListNode pre = newHead;
        ListNode cur = head;
        while(cur!=null){
            while(cur.next!=null&&cur.val==cur.next.val){
                cur = cur.next;
            }
            cur = cur.next;
            if(pre.next.next!=cur){
                pre.next = cur;
            }else{
                pre = pre.next;
            }
        }
        return newHead.next;
    }
}
